import env from '@/util/env.js'

// const URL = env.developmentUrl;
const URL = env.productionUrl;

const token = uni.getStorageSync("token")
const authorization = token ? `Bearer ${token}` : ""


function service(options = {}) {

	options.url = URL + options.url;

	return new Promise((resolve, reject) => {

		uni.request({
			url: options.url,
			method: options.method,
			data: options.data,
			header: {
				Authorization: authorization
			},
			success: (res) => {
				if (res.statusCode != 200) {
					uni.showToast({
						title: '数据获取失败',
						icon: 'error'
					})
				}
				console.log(res)
				resolve(res.data)
			},
			fail: (err) => {
				console.log(err)
				uni.showToast({
					title: '请求失败',
					icon: 'error'
				})
				console.log(err)
				reject(err)
			}
		});
	})
}
export default service;
